package com.cloud.elm.mapper;

import com.cloud.elm.po.DeliveryAddress;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DeliveryAddressMapper {

	@Select("select daId from last_delivery_address where userId = #{userId}")
	Integer getLastAddr(String userId);

	@Update("update last_delivery_address set daId = #{daId} where userId = #{userId}")
	int setLastAddr(String userId, Integer daId);

	@Insert("insert into last_delivery_address values (#{daId}, #{userId})")
	int addLastAddr(String userId, Integer daId);

	@Select("select * from deliveryaddress where userId=#{userId} order by daId")
    List<DeliveryAddress> listDeliveryAddressByUserId(String userId);
	
	@Select("select * from deliveryaddress where daId=#{daId}")
    DeliveryAddress getDeliveryAddressById(Integer daId);
	
	@Insert("insert into deliveryaddress values(null,#{contactName},#{contactSex},#{contactTel},#{address},#{userId})")
    int saveDeliveryAddress(DeliveryAddress deliveryAddress);
	
	@Update("update deliveryaddress set contactName=#{contactName},contactSex=#{contactSex},contactTel=#{contactTel},address=#{address} where daId=#{daId}")
    int updateDeliveryAddress(DeliveryAddress deliveryAddress);
	
	@Delete("delete from deliveryaddress where daId=#{daId}")
    int removeDeliveryAddress(Integer daId);

	@Delete("delete from last_delivery_address where daId=#{daId}")
	int removeLastDeliveryAddress(Integer daId);
}
